package com.cambright.mixpaint
{
	import flash.display.CapsStyle;
	import flash.display.JointStyle;
	import flash.display.LineScaleMode;
	
	public class Border extends Block
	{
		private var _graphicChanged:Boolean = true;
		
		private var _thinkness:int = 1;
		public function get thinkness():int
		{
			return _thinkness;
		}
		public function set thinkness(value:int):void
		{
			if(value < 0) value = 0;
			if(value == _thinkness) return;
			_thinkness = value;
			_graphicChanged = true;
		}
		
		override protected function get isChanged():Boolean
		{
			var isChanged:Boolean = super.isChanged;
			isChanged ||= _graphicChanged;
			return isChanged;
		}
		
		override protected function draw():void
		{
			var p:int = -_thinkness;
			var w:int = width + _thinkness * 2 - 1;
			var h:int = height + _thinkness * 2 - 1;
			
			graphics.clear();
			graphics.lineStyle(_thinkness, color, alpha, true, LineScaleMode.NONE, CapsStyle.SQUARE, JointStyle.MITER);
			if(round == 0) graphics.drawRect(p, p, w, h);
			else graphics.drawRoundRect(p, p, w, h, round);
		}
		
		override protected function finish():void
		{
			_graphicChanged = false;
		}
	}
}